package thread;


import java.util.Scanner;

//造成线程不安全的原因之一：内存可见性(编译器优化导致) 变量前添加volatile修饰，可以使该变量不被编译器优化，从而解决该问题
public class Demo15 {
    private  static int a = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            while(a == 0){

            }

            System.out.println("t1结束");
        });

        Thread t2 = new Thread(()->{
            Scanner sc = new Scanner(System.in);
            System.out.println("输入想要的a值：");
//            a = sc.nextInt();
            System.out.println("t2结束");
        });

        t1.start();
        t2.start();

    }
}
